#include <iostream>
#include <algorithm>

int const maxn = 50005;
double da[maxn], sum[maxn], sum_square[maxn];
int n, k;

int main()
{
	std::ios::sync_with_stdio(false);
	int T;
	std::cin >> T;
	while (T--) {
		std::cin >> n >> k;
		for (int i = 1; i <= n; i++) std::cin >> da[i];
		if (k == n) { std::cout << "0\n"; continue; }
		std::sort(da, da + n);
		for (int i = 0; i < n-k; i++) {
			sum[0] += da[i];
			sum_square[0] += da[i] * da[i];
		}
		double ans = 1<<29;
		for (int i = 1; i <= n; i++) {
			sum[i] = sum[i-1] + da[i];
			sum_square[i] = sum_square[i-1] + da[i]*da[i];
		}
		for (int i = 1; i <= k+1; i++) {
			double s1 = sum[i+n-k-1] - sum[i-1];
			double s2 = sum_square[i+n-k-1] - sum_square[i-1];
			double tmp = s2 - s1*s1 / (n-k);
			if (tmp < ans) ans = tmp;
		}
		std::cout << ans << '\n';
	}
}
